import pygame

pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False
white=(255,255,255)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)

bg = (127,127,127)
text=""
while not done:
   for event in pygame.event.get():
      screen.fill(bg)
      if event.type == pygame.QUIT:
         done = True
      if event.type == pygame.KEYDOWN:
         text=text+event.unicode
      font = pygame.font.SysFont("Arial", 36)
      img = font.render(text, True, white)
      rect = img.get_rect()
      cursor = pygame.Rect(rect.topright, (3, rect.height))
      img = font.render(text, True, white)
      rect.size=img.get_size()
      cursor.topleft = rect.topright
      screen.blit(img,(200 - img.get_width() // 2, 150 - img.get_height() // 2))
      pygame.display.update()